home *** CD-ROM | disk | FTP | other *** search
/ BCI NET 2 / BCI NET 2.iso / archives / misc / zxam16b.lha / ZXAM Spectrum / zxam_rexx / English / BatchConvert.zxam < prev    next >
Encoding:
Text File  |  1994-12-16  |  3.1 KB  |  119 lines

  1. /* This script converts all selected snapshots to the format you want */
  2.  
  3.     /* test if emulator is present */
  4.     address command
  5.     
  6.     if ~show(ports,ZXAM_REXX) then do
  7.         requestchoice '>nil: title "ZXAM Script error..." body "I can''t find the emulator''s port!!" gadgets "AARGH!"'
  8.         exit
  9.         end
  10.     
  11.     /* old window status */
  12.     oldname=zxamactname()
  13.     oldformat=zxamactformat()
  14.     oldsaveformat=zxamactsaveformat()
  15.     
  16.     /* ask for the files to be converted */
  17.     'requestfile >t:zxamconvert.tmp "'zxamactloadpath()'" title "Select snapshots to convert..." pattern 'zxamactpattern()' multiselect'
  18.     names=zxampploadfile('t:zxamconvert.tmp')
  19.     names=left(names,length(names)-1) /* discard LF */
  20.     
  21.     /* asf for destination drawer */
  22.     'requestfile >t:zxamconvert.tmp "'zxamactsavepath()'" drawersonly savemode'
  23.     destdrawer=zxampploadfile('t:zxamconvert.tmp')
  24.     destdrawer=strip(left(destdrawer,length(destdrawer)-1),'B','"') /* discard LF and " */
  25.     
  26.     /* ask for destination format */
  27.     requestchoice '>t:zxamconvert.tmp "ZXAM convert..."' '"What format do you want?"' GADGETS "PC|PC_PP|MIRAGE|MIRAGE_PP|CANCEL"
  28.     destformat=zxampploadfile('t:zxamconvert.tmp')
  29.     destformat=left(destformat,length(destformat)-1) /* discard LF */
  30.     
  31.     if names='' then exit
  32.     
  33.     if destformat=0 then exit /* CANCEL */
  34.     
  35.     if destformat=1 then do
  36.         destextension='.SP'
  37.         destformname='pc'
  38.         crunched=0
  39.         end
  40.  
  41.     if destformat=2 then do
  42.         destextension='.SP'
  43.         destformname='pc'
  44.         crunched=1
  45.         end
  46.         
  47.     if destformat=3 then do
  48.         destextension='.mirage'
  49.         destformname='mirage'
  50.         crunched=0
  51.         end
  52.         
  53.     if destformat=4 then do
  54.         destextension='.mirage'
  55.         destformname='mirage'
  56.         crunched=1
  57.         end
  58.     
  59.     ZXAMSaveFormat(destformname)    /* destination format */
  60.     
  61.     ZXAMEnableAbort()        /* enables the 'Abort ARexx' gadget */
  62.     
  63.     /* inside the loop we extract and process the selected files */
  64.     /* we change the extension of the file to the suitable for */
  65.     /* the destination format */
  66.     
  67.     do forever
  68.     name=strip(left(names,pos('"',names,2)),'B','"') /* extract the path&name */
  69.     nameonly=zxamfilepart(name)
  70.     
  71.     if ZXAMReadAbort() then signal cleanup
  72.     
  73.     /* process the file */
  74.     
  75.     zxamnameformat('Loading "'nameonly'"','Wait...')
  76.     
  77.     block=zxampploadfile(name)
  78.     origformat=zxamparseloaded(block)
  79.     
  80.     namenoext=nameonly
  81.     if lastpos('.',namenoext)~=0 then namenoext=left(namenoext,lastpos('.',namenoext)-1)
  82.     /* namenoext is the file name without extension */
  83.     
  84.     if origformat~='' then do
  85.             block=zxamparsetosave()
  86.             if crunched then
  87.                 do
  88.                 zxamnameformat('Compressing "'nameonly'"','Wait...')
  89.                 zxamppsavefile(zxamjoinpathname(destdrawer,namenoext)destextension,block)
  90.                 end
  91.             else 
  92.                 do
  93.                 zxamnameformat('Saving "'nameonly'"','Wait...')
  94.                 /* abrimos el fichero */
  95.                 if ~open('fichero',zxamjoinpathname(destdrawer,namenoext)destextension,'W') then signal cleanup
  96.     
  97.                 /* write the snapshot to the file */
  98.                 dummy=writech('fichero',block)
  99.     
  100.                 dummy=close('fichero')
  101.                 end
  102.         end
  103.     
  104.     if pos('"',names,2)=length(names) then signal cleanup /* end of list */
  105.     names=right(names,length(names)-(length(name)+3))
  106.     
  107.     end
  108.     
  109.     
  110. cleanup:
  111.     if oldname='' then
  112.         zxamclearnameformat()
  113.     else
  114.         zxamnameformat(oldname,oldformat)
  115.  
  116.     zxamsaveformat(oldsaveformat)
  117.     
  118.     exit
  119.